package main

import "fmt"

type Humaner interface {
	SayHi()
}

//Student实现SayHi()方法
type Student struct {//老师
	name string
	score float64
}

func (s *Student) SayHi() {
	fmt.Printf("Student[%s, %f] say hi!!\n", s.name, s.score)
}

type Teacher struct {
	name string
	group string
}

//Teacher实现SayHi()方法
func (t *Teacher) SayHi() {
	fmt.Printf("Teacher[%s, %s] say hi!!\n", t.name, t.group)
}

type MyStr string

//MyStr实现SayHi()方法
func (str MyStr) SayHi() {
	fmt.Printf("MyStr[%s] say hi!!\n", str)
}

//普通函数，参数为Humaner类型的变量i
func WhoSayHi(i Humaner) {
	i.SayHi()
}

func main() {
	s := &Student{"mike", 88.5}
	t := &Teacher{"yogo", "Go 语言"}
	var tmp MyStr = "测试"

	s.SayHi()
	t.SayHi()
	tmp.SayHi()

	//多态
	WhoSayHi(s)
	WhoSayHi(t)
	WhoSayHi(tmp)

	x := make([]Humaner, 3)
	//这三个都是不同类型的元素,但是他们实现了interface同一个接口
	x[0], x[1], x[2] = s, t, tmp
	for _,value := range x {
		value.SayHi()
	}

}